package com.lixinlei.jedis.demo.bloomfilter;


import io.rebloom.client.Client;

public class BloomFilterDemo {

    public static void main(String[] args) {
        judgeUnseenElements();
    }

    private static void judgeSeenElements() {

        Client client = new Client("", 6379);

        client.delete("codehole");
        for (int i = 0; i < 10000; i++) {
            client.add("codehole", "user" + i);

            // 对于见过的 value，BloomFilter 是不会误判的
            boolean ret = client.exists("codehole", "user" + i);
            if (!ret) {
                System.out.println(i);
                break;
            }
        }
    }

    private static void judgeUnseenElements() {

        Client client = new Client("", 6379);

        client.delete("codehole");
        for (int i = 0; i < 10000; i++) {
            client.add("codehole", "user" + i);

            // 对于没见过的 value，BloomFilter 可能误判
            boolean ret = client.exists("codehole", "user" + (i + 1));
            if (ret) {
                System.out.println(i); // 310
                break;
            }
        }
    }

}
